package com.ythook.mentor.service;

import com.ythook.mentor.entity.MentorCalendar;
import com.ythook.mentor.repository.MentorCalendarRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class MentorCalendarService {
    @Resource
    private MentorCalendarRepository mentorCalendarRepository;

    public List<MentorCalendar> search() {
        return mentorCalendarRepository.findAll();
    }

    public Optional<MentorCalendar> findById(Long id) {
        return mentorCalendarRepository.findById(id);
    }

    public Optional<MentorCalendar> findByMentorId(Long mentorId) {
        Optional<MentorCalendar> mentorCalendar = Optional.of(mentorCalendarRepository.findAllByMentorId(mentorId).orElse(new MentorCalendar()));
        return mentorCalendar;
    }

    public void delete(Long id) {
        mentorCalendarRepository.deleteById(id);
    }

    public MentorCalendar add(MentorCalendar mentorCalendar) {
        return mentorCalendarRepository.save(mentorCalendar);
    }

    public MentorCalendar update(MentorCalendar mentorCalendar) {
        return mentorCalendarRepository.save(mentorCalendar);
    }
}
